<template>
  <div>
    <MessageWinComponent ref="message-win"/>
    <div class="mc-recipe-main">
      <div class="mv-recipe-part-div">
        <ToolBarComponent ref="queryRecipeBar" bar-ref-name="operBar" min-height="70px">
          <Button text="合成表查询" :click-function="recipeQuery"/>
          <Button text="Excel导出" :click-function="recipeExcelExport"/>
          <NumberInputComponent input-lable="合成量" input-name="processNum" defaule-value="1"/>
        </ToolBarComponent>
        <!--   物品查询列表   -->
        <GridComponent
            ref="mcItemNum"
            :auto-load="false"
            key-property-name="id"
            grid-name="mcItemNumGrid"
            select-moduel="single"
            max-height-prop="40%"
            :paging-moduel="false"
        >
          <GridColumnComponent width="400px" column-name="物品名称" index-name="dictName"/>
          <GridColumnComponent width="250px" column-name="物品数量" index-name="dictNum"/>
        </GridComponent>
        <div class="mc-recipe-tree-div">
          <DataTree ref="tree"/>
        </div>
      </div>
      <div class="mv-recipe-part-div">
        <ToolBarComponent ref="queryBar" bar-ref-name="queryBar" min-height="70px">
            <InputComponent input-lable="合成物名称" input-name="materialNameLike" input-type="text"/>
            <Button text="查询" :click-function="dictQuery"/>
        </ToolBarComponent>
        <!--   物品查询列表   -->
        <GridComponent
          ref="mcItemGrid"
          :auto-load="true"
          key-property-name="id"
          grid-name="mcItemInfoGrid"
          select-moduel="single"
          load-url="mcgame/dictQuery.do"
          max-height-prop="85%"
          :paging-moduel="true"
        >
          <GridColumnComponent width="350px" column-name="物品名称" index-name="dictName"/>
          <GridColumnComponent width="250px" column-name="MOD所属" index-name="modName"/>
        </GridComponent>
      </div>
    </div>
  </div>
</template>

<script>
import DataTree from "@/components/tree/dataTree/DataTree";
import ToolBarComponent from "@/components/toolbar/ToolBarComponent";
import Button from "@/components/button/ButtonComponent";
import InputComponent from "@/components/input/InputComponent";
import GridComponent from "@/components/grid/GridComponent";
import GridColumnComponent from "@/components/grid/GridColumnComponent";
import {postRequest} from "@/axio2";
import NumberInputComponent from "@/components/input/NumberInputComponent";
import MessageWinComponent from "@/components/win/MessageWinComponent";

export default {
  name: "McRecipePage",
  components: {
    MessageWinComponent,
    NumberInputComponent,
    GridColumnComponent, GridComponent, InputComponent, Button, ToolBarComponent, DataTree},
  data(){
    return{
      showDisplay:'none'
    }
  },
  methods:{
    dictQuery(){
      let param = this.$refs["queryBar"].getSubmitParams();
      console.log(param);
      this.$refs["mcItemGrid"].addQueryParams(param);
      this.$refs["mcItemGrid"].load();
    },
    recipeQuery(){
      let dict = this.$refs["mcItemGrid"].getSelectData();
      let processNum = this.$refs["queryRecipeBar"].getSubmitParams();
      if(undefined===processNum["processNum"]){
        processNum["processNum"] = '1';
      }
      if(undefined!==dict && dict.length>0){
        let param = {'meterialId':dict[0].id, 'meterialName':dict[0].dictName};
        Object.assign(param,processNum);
        postRequest(
            "mcgame/meterialCount.do",
            param,
            this.recipeQuerySuccessCallBack,
            this.recipeQueryFailResult,
            this
        );
      }
    },
    recipeQueryFailResult(respData,component){
      let msgWin = component.$refs["message-win"];
      msgWin.setMessage(respData.data.errorMsg);
      msgWin.showWin();
    },
    recipeExcelExport(){
      let dict = this.$refs["mcItemGrid"].getSelectData();
      let processNum = this.$refs["queryRecipeBar"].getSubmitParams();
      if(undefined!==dict && dict.length>0){
        let param = {'meterialId':dict[0].id, 'meterialName':dict[0].dictName};
        Object.assign(param,processNum);
        postRequest(
            "mcgame/meterialExcel.do",
            param,
            this.recipeQuerySuccessCallBack,
            null,
            this
        );
      }
    },
    recipeQuerySuccessCallBack(respData,component){
      let obj = JSON.parse(respData.data.errorMsg);
      component.$refs["tree"].setTreeData(obj.recipeResultDTO);
      let oriMap = obj.oriMaterialMap;
      let oriData = [];
      for(let i in oriMap){
        oriData.push({dictName:i,dictNum:oriMap[i]})
      }
      component.$refs["mcItemNum"].setOutData(oriData);
    }
  }
}
</script>

<style scoped>
.mc-recipe-main{
  height: 100%;
  width: 100%;
}
.mv-recipe-part-div{
  vertical-align: top;
  display: inline-block;
  height: 100%;
  width: 48%;
  border-left: 1px #2c3e50 solid;
  border-right: 1px #2c3e50 solid;
}
.mc-recipe-tree-div{
  overflow-y:scroll;
  height: 45%;
  padding-top: 10px;
  border-top: 1px #2c3e50 solid;
  border-bottom: 1px #2c3e50 solid;
}
</style>